added Feb 2001 SDK
[windows-sources.git] / shared source / vb / language / shared / tristate.h
blob32844002d05d61fcd5989fb6534a1a165ee7e732
1 //-------------------------------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 //-------------------------------------------------------------------------------------------------
7 #pragma once
9 template <class T>
10 class TriState
12 public:
13 TriState() :
14 m_hasValue(false)
18 TriState(T value) :
19 m_hasValue(true),
20 m_value(value)
24 ~TriState()
28 bool HasValue() const
30 return m_hasValue;
33 const T& GetValue() const
35 ThrowIfFalse(HasValue());
36 return m_value;
39 T& GetValue()
41 ThrowIfFalse(HasValue());
42 return m_value;
45 T GetValueOrDefault( _In_ const T& defaultValue) const
47 if ( !HasValue() )
49 return defaultValue;
51 return m_value;
54 void SetValue(T value)
56 m_value = value;
57 m_hasValue = true;
60 void ClearValue()
62 ClearValue(T());
65 void ClearValue(const T& defaultValue)
67 m_hasValue = false;
68 m_value = defaultValue;
71 private:
72 bool m_hasValue;
73 T m_value;